//
// Created by Hoyin on 2024/4/16.
//

#ifndef VISUAL_LOCATION_PARTIMATCHER_H
#define VISUAL_LOCATION_PARTIMATCHER_H

#include <opencv2/core.hpp>
#include <opencv2/features2d.hpp>
#include <iostream>
#include "utils.h"


class PartiMatcher {
private:
	cv::BFMatcher _matcher;

	double _minDistThreshold;

	static void _calcExtendedROIs(const std::vector<cv::Rect> &blocks, uint32_t roiIdx, uint32_t hParts, uint32_t vParts, std::vector<cv::Rect> &extended_rois_dst);

	static std::vector<uint32_t> _extendedROIs(int roiIdx, int columns, int rows);

	static bool pointInBlocks(const cv::Point &interestPoint, const std::vector<cv::Rect> &rois);

	static cv::Mat calcMask(const std::vector<cv::KeyPoint>& keypoints1, const std::vector<cv::KeyPoint>& keypoints2,
							const std::vector<cv::Rect>& blocks, uint32_t roiIdx, uint32_t hParts, uint32_t vParts);

public:
	PartiMatcher(cv::BFMatcher &matcher, double minDist=20) {
		_matcher = matcher;
		_minDistThreshold = minDist;
	}

	void match(const std::vector<cv::KeyPoint>& keypoints1, const std::vector<cv::KeyPoint>& keypoints2,
	           const cv::Mat& descriptor1, const cv::Mat& descriptor2,
	           const std::vector<cv::Rect>& blocks, std::vector<cv::DMatch> &matches,
	           const cv::Mat &src1, const cv::Mat &src2, uint32_t hParts, uint32_t vParts);
};


#endif //VISUAL_LOCATION_PARTIMATCHER_H
